<?php
declare (strict_types = 1);
namespace app\course\model\base;

use app\common\model\BaseModel;
use app\user\model\user\Account;
use think\model\relation\BelongsTo;

/**
 * 定义课程学员数据模型
 */
class CourseWareRecord extends BaseModel
{
    /**
     * 表名
     * @var string
     */
    protected $name = 'course_courseware_record';

    /**
     * 定义字段类型
     * @var array
     */
    protected $type = [
        'id'        => 'integer',
        'user_id'   => 'integer',
        'course_id' => 'integer',
        'ware_id'   => 'integer',
        'count'     => 'integer',
    ];

//关联

    /**
     * 关联用户
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-06-30
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(Account::class, 'user_id');
    }

    /**
     * 关联课程
     */
    public function course(): BelongsTo
    {
        return $this->belongsTo(Course::class, 'course_id')->bind(['course_title' => 'title']);
    }

}
